<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
require_once  '../classes/ConnectionDB.php';
require_once  '../classes/UtenteManager.php';
require_once  '../classes/TestDataManager.php';
require_once  '../classes/TestManager.php';
require_once  '../bean/Domanda.php';

$connection =ConnectionDB::getInstance()->connectToDB();
$codiceTest = $_GET['codiceTest'];
$key = $_GET['key'];
$codiceStudente = $_GET["codiceStudente"];

$risultati = TestDataManager::getInstance()->getRisposteDate ($connection, $codiceStudente, $codiceTest, $key);

?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Report domande test</title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");
            table{
                width: 100%;
            }

            #tableResults td{
                text-align: center;
            }


            #results {
                padding-top: 3%;

            }

            #resultsCont
            {

            }

            #navigator
            {
                font-size: 14px;
            }

        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaDomande;
            var numItem=8;
            var currentIndex=0;
            var i=0;

            window.onload = function()
            {

                var results = new GlassBox();
                results.init( 'results', '1040px', '470px', 'auto','',true,false);
                results.ipos();
                results.appear();

            }


        </script>
    </head>
    <body>

        <?php include '../portal/header.php';?>
        <center>
            <div id="results">
                <div id="resultsCont">
                    <table width="100%" border="1">
                        <tr>
                            <th>Dettaglio domanda</th>
                            <th>Codice domanda</th>
                            <th>Testo domanda</th>
                            <th>Risposta corretta</th>
                            <th>Risposta Data</th>
                            <th>Punteggio domanda</th>
                        </tr>
                        <? for($i=0; $i<count($risultati); $i++)
                        {
                            $domanda = TestDataManager::getInstance()->getDomanda($connection, $risultati[$i]->getCodiceDomanda());
                            $rispostaCorretta = TestDataManager::getInstance()->getRispostaCorretta($connection, $risultati[$i]->getCodiceDomanda(), $domanda->getTipologia());

                            $color = 'red';
                            if($domanda->getTipologia()=='1')
                            {
                                if($risultati[$i]->getRispostaData()!="" && $risultati[$i]->getRispostaData()== $rispostaCorretta)
                                    $color='green';
                            }
                            else
                            {
                                //$rispostaStr = TestDataManager::getInstance()->getRispostaCorrettaStr($connection, $rispostaCorretta, $risultati[$i]->getCodiceDomanda());
                                $seedAlternative = TestDataManager::getInstance()->getSeedAlternative($connection, $codiceTest, $codiceStudente, $domanda->getCodiceDomanda());
                                $tmpSeed = explode("-", $seedAlternative);

                                if($risultati[$i]->getRispostaData() != "")
                                  $rispFromSeed=$tmpSeed[$risultati[$i]->getRispostaData()-1];

                                if($risultati[$i]->getRispostaData()!="" && $rispFromSeed == $rispostaCorretta)
                                    $color='green';

                            }

                            ?>
                        <tr>
                            <td style="text-align: center" bgcolor="<?= $color ?>"><img src='../images/icons/PNG/Magnifying Glass.png' height='30' width='30' title='Risultati' onclick='javascript:location.href="../report/detailQuestion.php?codiceDomanda=<?= $domanda->getCodiceDomanda() ?>"' border='0' /></td>
                            <td style="text-align: center" bgcolor="<?= $color ?>"><?= $domanda->getCodiceDomanda() ?></td>
                            <td style="text-align: center" bgcolor="<?= $color ?>"><?= $domanda->getTestoDomanda() ?></td>
                                <?  if($domanda->getTipologia()=='1')
                                {?>
                            <td style="text-align: center" bgcolor="<?= $color ?>"><? if ($rispostaCorretta =='V') echo 'Vero'; else echo 'Falso'; ?></td>
                            <td style="text-align: center" bgcolor="<?= $color ?>"><? if($risultati[$i]->getRispostaData() == "") echo '&nbsp;'; else if($risultati[$i]->getRispostaData()=='V') echo 'Vero'; else echo 'Falso'; ?></td>
                                    <?}else
                                {?>
                            <td style="text-align: center" bgcolor="<?= $color ?>">
                                        <? if($rispostaCorretta == '1') echo 'Alternativa 1';
                                        if($rispostaCorretta == '2') echo 'Alternativa 2';
                                        if($rispostaCorretta == '3') echo 'Alternativa 3';
                                        if($rispostaCorretta == '4') echo 'Alternativa 4';
                                        ?>
                            </td>
                            <td style="text-align: center" bgcolor="<?= $color ?>">
                                        <? if($risultati[$i]->getRispostaData() == "")
                                                  echo '&nbsp;';
                                        else
                                        {
                                            if ($rispFromSeed =='1') echo 'Alternativa 1';
                                            if ($rispFromSeed =='2') echo 'Alternativa 2';
                                            if ($rispFromSeed =='3') echo 'Alternativa 3';
                                            if ($rispFromSeed =='4') echo 'Alternativa 4';
                                        }?>
                            </td>
                                    <?}?>

                            
                            <td style="text-align: center" bgcolor="<?= $color ?>" style="text-align: center"><?= $domanda->getPunteggio() ?></td>

                        </tr>
                            <?}?>
                    </table>

                </div>

            </div>
        </center>
    </body>
</html>
